﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Arizu.DAL;

namespace Arizu.Repository
{
    public class AirizuIndent : BaseProvider
    {
        #region
        private static volatile AirizuIndent instance;
        private static object lockHelper = new object();

        private AirizuIndent()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static AirizuIndent CreateInstance()
        {
            if (instance == null)
            {
                lock (lockHelper)
                {
                    if (instance == null)
                    {
                        instance = new AirizuIndent();
                    }
                }
            }
            return instance;
        }
        #endregion

        public DataTable GetOrderOnTime(long userId, long currentTime)
        {
            DataTable dt = new DataTable();
            string sql = "select * from Indent where UserId=" + userId + " and StartTime<" + currentTime + " and EndTime>" + currentTime;

            try
            {
                dt = SqlHelper.ExecuteDataset(conn, CommandType.Text, sql).Tables[0];
            }
            catch (Exception)
            {

                throw;
            }

            return dt;
        }

        public DataTable GetOrderBefore(long userId, long currentTime)
        {
            DataTable dt = new DataTable();
            string sql = "select * from Indent where UserId=" + userId + " and EndTime<" + currentTime;

            try
            {
                dt = SqlHelper.ExecuteDataset(conn, CommandType.Text, sql).Tables[0];
            }
            catch (Exception)
            {

                throw;
            }

            return dt;
        }

        public DataTable GetOrderOnAfter(long userId, long currentTime)
        {
            DataTable dt = new DataTable();
            string sql = "select * from Indent where UserId=" + userId + " and StartTime>" + currentTime;

            try
            {
                dt = SqlHelper.ExecuteDataset(conn, CommandType.Text, sql).Tables[0];
            }
            catch (Exception)
            {

                throw;
            }

            return dt;
        }

        public DataTable GetOwnerOrderOnAfter(long userId, long currentTime)
        {
            DataTable dt = new DataTable();
            string sql = "select * from Indent where OwnerId=" + userId + " and StartTime>" + currentTime;

            try
            {
                dt = SqlHelper.ExecuteDataset(conn, CommandType.Text, sql).Tables[0];
            }
            catch (Exception)
            {

                throw;
            }

            return dt;
        }

        public DataTable GetOrderOnAfterByRoomId(long roomId, long currentTime)
        {
            DataTable dt = new DataTable();
            string sql = "select * from Indent where RoomID=" + roomId + " and StartTime>" + currentTime;

            try
            {
                dt = SqlHelper.ExecuteDataset(conn, CommandType.Text, sql).Tables[0];
            }
            catch (Exception)
            {

                throw;
            }

            return dt;
        }

        public DataTable GetIndentCount(string roomId)
        {
            DataTable dt = new DataTable();
            string sql = "select count(*) from Indent where RoomID=" + roomId;

            try
            {
                dt = SqlHelper.ExecuteDataset(conn, CommandType.Text, sql).Tables[0];
            }
            catch (Exception)
            {

                throw;
            }

            return dt;
        }

        public DataTable IsAvailable(long roomId, long p, long p_3)
        {
            DataTable dt = new DataTable();
            string sql = "select count(*) from Indent where RoomID=" + roomId + " and StartTime>" + p + " and EndTime<" + p_3;

            try
            {
                dt = SqlHelper.ExecuteDataset(conn, CommandType.Text, sql).Tables[0];
            }
            catch (Exception)
            {

                throw;
            }

            return dt;
        }
    }
}
